#include "stdafx.h"
#ifdef _DEBUG
	#undef THIS_FILE
	static char THIS_FILE[] = __FILE__;
	#define new DEBUG_NEW
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////
BOOL StreamToRds(_RecordsetPtr&pRds,LPSTR strData,DWORD dwSize)
{
	IStream*pStm = NULL;
	DWORD cbWritten,rtCode(0);
	const LARGE_INTEGER li0 = {0, 0};
	ULARGE_INTEGER uli = {0,0};
	try
	{
		if(pRds==NULL)
		{
			pRds.CreateInstance(__uuidof(Recordset));
			pRds->CursorLocation = adUseClient;
		}
		else
		{
			if(pRds->GetState()==adStateOpen) pRds->Close();
		}
	}
	catch(...)
	{
	}
	try
	{
		if(dwSize)
		{
			CreateStreamOnHGlobal(NULL,TRUE,&pStm);
			pStm->Write(strData,dwSize,&cbWritten);
			pStm->Seek(li0,STREAM_SEEK_SET,&uli);
			_variant_t vNull(DISP_E_PARAMNOTFOUND,VT_ERROR);
			pRds->PutRefActiveConnection(NULL);
			pRds->CursorLocation = adUseClient;
			pRds->Open(pStm,vNull,adOpenStatic,adLockBatchOptimistic,adOpenUnspecified);
			pRds->PutRefActiveConnection(NULL);
		}
		rtCode = TRUE;
	}
	catch(...)
	{
		rtCode = FALSE;
	}
	if(pStm)
	{
		try
		{
			pStm->Release();
		}
		catch(...)
		{
		}
	}
	return(rtCode);
}
